// 引入哈希库
function md5(str) {
    return CryptoJS.MD5(CryptoJS.enc.Utf8.parse(str)).toString();
}

function keccak384(str) {
    return CryptoJS.SHA3(str, { outputLength: 384 }).toString();
}

document.getElementById('calculateButton').addEventListener('click', function () {
    const code = document.getElementById('machineCode').value;
    const version = document.getElementById('versionSelect').value;
    const resultDiv = document.getElementById('result');
    resultDiv.innerHTML = '';

    if (!code) {
        resultDiv.innerHTML = '<p class="text-red-500">请输入机器码！</p>';
        return;
    }

    switch (version) {
        case "3.9.5":
            resultDiv.innerHTML += `<p class="text-green-500">高级版: ${md5(`61305${code}8552`).slice(8, 24)}</p>`;
            resultDiv.innerHTML += `<p class="text-green-500">专业版: ${md5(`2356${code}13593`).slice(8, 24)}</p>`;
            break;
        case "3.9.6":
            resultDiv.innerHTML += `<p class="text-green-500">高级版: ${keccak384(`${code}hSf(78cvVlS5E`).slice(12, 28)}</p>`;
            resultDiv.innerHTML += `<p class="text-green-500">专业版: ${keccak384(`${code}FF3Go(*Xvbb5s2`).slice(12, 28)}</p>`;
            break;
        case "4.5":
            resultDiv.innerHTML += `<p class="text-green-500">高级版: ${keccak384(`${code}S3&*sbLbr`).slice(12, 28)}</p>`;
            resultDiv.innerHTML += `<p class="text-green-500">专业版: ${keccak384(`${code}23Sfr3k&sc`).slice(12, 28)}</p>`;
            break;
        case "4.5.11":
            resultDiv.innerHTML += `<p class="text-green-500">高级版: ${keccak384(`${code}wcegS3gzA$`).slice(12, 28)}</p>`;
            resultDiv.innerHTML += `<p class="text-green-500">专业版: ${keccak384(`${code}b(xxkHn%z);x`).slice(12, 28)}</p>`;
            break;
        default:
            resultDiv.innerHTML = '<p class="text-red-500">无效的版本号！</p>';
    }
    resultDiv.innerHTML += `<p class="text-yellow-500">来源: QQ群【740641908】提供免费激活码</p>`;
    resultDiv.innerHTML += `<p class="text-red-500">本程序仅供学习研究使用，</p>`;
    resultDiv.innerHTML += `<p class="text-red-500">严禁用于商业用途或非法目的。</p>`;
    resultDiv.innerHTML += `<p class="text-red-500">使用产生的任何风险由使用者自行承担，</p>`;
    resultDiv.innerHTML += `<p class="text-red-500">作者不承担任何法律责任！</p>`;
});